/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh 
 												
Class							:				Metric Buildings
 
Function						: 				Holding the metrics for buildings. Used in 
												the distance calculation for CBR
****************************************************************************/
package cbr.metrics;

import base.WargusPlayer;
import base.WargusStateImporter;
import base.WargusUnit;

public class MetricBuildings {
	float m_numTownHalls;
	float m_numBarracks;
	float m_numLumberMills;
	float m_numBlackSmith;
	float m_numAdvancedBuilding;
	float m_numFarms;
	float m_numTowers;
	
	public void setnumTownHalls(float val){m_numTownHalls = val;}
	public void setnumBarracks(float val){m_numBarracks = val;}
	public void setnumLumberMills(float val){m_numLumberMills = val;}
	public void setnumBlackSmith(float val){m_numBlackSmith= val;}
	public void setnumAdvancedBuilding(float val){m_numAdvancedBuilding= val;}
	public void setnumFarms(float val){m_numFarms = val;}
	public void setnumTowers(float val){m_numTowers = val;}

	public float getnumTownHalls(){return m_numTownHalls;}
	public float getnumBarracks(){return m_numBarracks;}
	public float getnumLumberMills(){return m_numLumberMills;}
	public float getnumBlackSmith(){return m_numBlackSmith;}
	public float getnumAdvancedBuilding(){return m_numAdvancedBuilding;}
	public float getnumFarms(){return m_numFarms;}
	public float getnumTowers(){return m_numTowers;}
	
	public MetricBuildings() {
		m_numTownHalls = 0;
		m_numBarracks = 0;
		m_numLumberMills = 0;
		m_numBlackSmith = 0;
		m_numAdvancedBuilding = 0;
		m_numFarms = 0;
		m_numTowers = 0;	
	}	
	
	public MetricBuildings(WargusPlayer p) {
		m_numTownHalls = 0;
		m_numBarracks = 0;
		m_numLumberMills = 0;
		m_numBlackSmith = 0;
		m_numAdvancedBuilding = 0;
		m_numFarms = 0;
		m_numTowers = 0;	
		
		if (p!=null) {		
			for(WargusUnit u : p.getUnits()) {
				
				if(u.getType()==WargusStateImporter.unitTypeToInteger("stronghold") ||
			 	   u.getType()==WargusStateImporter.unitTypeToInteger("fortress") ||
				   u.getType()==WargusStateImporter.unitTypeToInteger("castle") ||
				   u.getType()==WargusStateImporter.unitTypeToInteger("keep") ||
				   u.getType()==WargusStateImporter.unitTypeToInteger("town-hall") ||
				   u.getType()==WargusStateImporter.unitTypeToInteger("great-hall")) {
					m_numTownHalls++;
				}
				else if (u.getType()==WargusStateImporter.unitTypeToInteger("pig-farm") ||
						 u.getType()==WargusStateImporter.unitTypeToInteger("farm")) {
					m_numFarms++;
				}
				else if (u.getType()==WargusStateImporter.unitTypeToInteger("elven-lumber-mill") ||
						 u.getType()==WargusStateImporter.unitTypeToInteger("troll-lumber-mill")) {
					m_numLumberMills++;
				}
				else if (u.getType()==WargusStateImporter.unitTypeToInteger("orc-barracks") ||
						 u.getType()==WargusStateImporter.unitTypeToInteger("human-barracks")) {
					m_numBarracks++;
				}
				else if (u.getType()==WargusStateImporter.unitTypeToInteger("human-blacksmith") ||
						 u.getType()==WargusStateImporter.unitTypeToInteger("orc-blacksmith")) {
					m_numBlackSmith++;
				}			
			}
		}
	}
	
	// This alternative constructor is used to add the metrics of several players together:
	public MetricBuildings(WargusPlayer p,MetricBuildings m) {
		if (m!=null) {
			m_numTownHalls = m.m_numTownHalls;
			m_numBarracks = m.m_numBarracks;
			m_numLumberMills = m.m_numLumberMills;
			m_numBlackSmith = m.m_numBlackSmith;
			m_numAdvancedBuilding = m.m_numAdvancedBuilding;
			m_numFarms = m.m_numFarms;
			m_numTowers = m.m_numTowers;		
		} else {
			m_numTownHalls = 0;
			m_numBarracks = 0;
			m_numLumberMills = 0;
			m_numBlackSmith = 0;
			m_numAdvancedBuilding = 0;
			m_numFarms = 0;
			m_numTowers = 0;			
		}
		
		for(WargusUnit u : p.getUnits()) {
			
			if(u.getType()==WargusStateImporter.unitTypeToInteger("stronghold") ||
		 	   u.getType()==WargusStateImporter.unitTypeToInteger("fortress") ||
			   u.getType()==WargusStateImporter.unitTypeToInteger("castle") ||
			   u.getType()==WargusStateImporter.unitTypeToInteger("keep") ||
			   u.getType()==WargusStateImporter.unitTypeToInteger("town-hall") ||
			   u.getType()==WargusStateImporter.unitTypeToInteger("great-hall")) {
				m_numTownHalls++;
			}
			else if (u.getType()==WargusStateImporter.unitTypeToInteger("pig-farm") ||
					 u.getType()==WargusStateImporter.unitTypeToInteger("farm")) {
				m_numFarms++;
			}
			else if (u.getType()==WargusStateImporter.unitTypeToInteger("elven-lumber-mill") ||
					 u.getType()==WargusStateImporter.unitTypeToInteger("troll-lumber-mill")) {
				m_numLumberMills++;
			}
			else if (u.getType()==WargusStateImporter.unitTypeToInteger("orc-barracks") ||
					 u.getType()==WargusStateImporter.unitTypeToInteger("human-barracks")) {
				m_numBarracks++;
			}
			else if (u.getType()==WargusStateImporter.unitTypeToInteger("human-blacksmith") ||
					 u.getType()==WargusStateImporter.unitTypeToInteger("orc-blacksmith")) {
				m_numBlackSmith++;
			}			
		}
	}	
}
